package com.design.pattern.creational.simplefactory;

/**
 * description
 *
 * @author RenQiQiang 2019/02/15 9:42
 */
public class ProductFactory {

    public Product getProduct(Class c){
        Product product = null;
        try {
            product = (Product) Class.forName(c.getName()).newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return product;
    }

    public Product getProduct(String type){
        if ("java".equalsIgnoreCase(type)){
            return new JavaProduct();
        }else if ("python".equalsIgnoreCase(type)){
            return new PythonProduct();
        }
        return null;
    }
}
